package com.duan.laugh.starter.email;


import java.util.List;

/**
 * 配置文件中的邮箱账户
 *
 * @author duanjw
 */
public class PropertiesEmailAccountLocator implements EmailAccountLocator {
    private EmailProperties emailProperties;

    public PropertiesEmailAccountLocator(EmailProperties emailProperties) {
        this.emailProperties = emailProperties;
    }

    /**
     * 所有邮箱账户
     * @return
     */
    @Override
    public List<EmailAccount> getEmailAccounts() {
        return emailProperties.getAccounts();
    }

    /**
     * 根据邮箱账户id获取邮箱账户
     * @param id
     * @return
     */
    @Override
    public EmailAccount getEmailAccount(String id) {
        return emailProperties.getAccounts().stream().filter(r -> r.getId().equals(id)).findFirst().orElse(null);
    }
}
